<?php


	class ShopGoodsController extends CommonController{

		public $model;

		public function __init(){
			parent:: __init();
			$this->model = K('Shop_goods');
		}

		public function index(){
			//调商品表的数据
			$goodsData = $this->model->all();
			// p($goodsData);die;
			$this->assign('goodsData',$goodsData);


			$this->display();

		}

		public function goods_add(){
			//页面中的数据的调出
			//所属品牌
			$brandData = K('Shop_brand')->all();

			$this->assign('brandData',$brandData);
			//所属的类型
			$CategoryData = K('Shop_category')->all();
			// p($CategoryData);
			$CategoryData = Data::tree($CategoryData,'cname','cid','pid');
			// p($CategoryData);die;
			$this->assign('CategoryData',$CategoryData);
			
			

			
			//添加的方法
			if (IS_POST) {

				if (!$this->model->add_data()) {
					$this->error($this->model->error);
				}
				$this->success('数据添加成功');
				
						
			}

			$this->display();
			
		}

		public function del(){
			$gid = Q('get.gid',0,'intval');
			// p($gid);die;
			$this->model->del($gid);
			K('Shop_detail')->where("shop_goods_gid={$gid}")->del();
			K('Shop_goods_attr')->where("shop_goods_gid={$gid}")->del();
			$this->success('删除商品成功');

		}

		public function up(){
			
			$tid = $_POST['id'];
			$attrData = K('Shop_type_attr')->where("shop_type_tid={$tid}")->all();
			
			
			foreach ($attrData as $k => $v) {
				//用explode分割成数组
				$attrData[$k]['tavalue'] = explode('|', $v['tavalue']);
				
			}
			// p($attrData);die;
			$this->ajax($attrData);
			
		}
		//最好区分两个上传图片的方法
		//上传缩略图的方法
		public function upload()
		{
		    $upload = new Upload('Upload/Content/' . date('y/m'));
		    $file = $upload->upload();
		    if (empty($file)) {
		        $this->ajax('上传失败');
		    } else {
		        $data = $file[0];
		        $this->ajax($data);
		    }
		}

		//上传商品图册的方法
		public function upload_tuce()
		{
		    $upload = new Upload('Upload/Content_tuce/' . date('y/m'));
		    $file = $upload->upload();
		    if (empty($file)) {
		        $this->ajax('上传失败');
		    } else {
		        $data = $file[0];
		        $this->ajax($data);
		    }
		}

		//上传商品实拍的方法
		public function upload_shipai()
		{
		    $upload = new Upload('Upload/Content_shipai/' . date('y/m'));
		    $file = $upload->upload();
		    if (empty($file)) {
		        $this->ajax('上传失败');
		    } else {
		        $data = $file[0];
		        $this->ajax($data);
		    }
		}
	}


















?>